package aryn.framework.display;

import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;

import aryn.framework.utilities.Util;

public class CursorsHandler {

	private Toolkit tk = Toolkit.getDefaultToolkit();
	private Cursor[] cursors;

	public CursorsHandler(int cursorsDimension) {
		cursors = new Cursor[cursorsDimension];
	}
	
	public long addCursor(String cursorPath, int pointX, int pointY, String cursorName) {
		Image cursorImage = tk.getImage(cursorPath);
		Cursor cursor = tk.createCustomCursor(cursorImage, new Point(pointX, pointY), cursorName);
		int index = Util.findFirstNull(cursors);
		cursors[index] = cursor;
		return index;
	}
	
	public long addCursor(String cursorPath) {
		return addCursor(cursorPath, 0, 0, cursorPath);
	}
	
	public Cursor getCursor(int id) {
		return cursors[id];
	}
	
	// not tested
	public void setCursorsSize(int size) {
		Cursor[] newCursors = new Cursor[size];
		int lastValue = Util.findLastNotNull(cursors);
		System.arraycopy(cursors, 0, newCursors, 0, Math.min(lastValue, newCursors.length));
		cursors = newCursors;
	}
}
